/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package horizon.network;

import horizon.entity.Entity;
import horizon.entity.Player;
import horizon.util.Vector2;
import java.util.StringTokenizer;

/**
 *
 * @author J_Laptop
 */
public class EntityEncoder {

    public static Entity createEntity(String s) {

        StringTokenizer str = new StringTokenizer(s, ":");
        String type = str.nextToken();
        String id = str.nextToken();
        String posX = str.nextToken();
        String posY = str.nextToken();

        Entity e = null;
        if(type.equals("1")){
            
            e = new Player(id , null);
            
        }
        e.position = new Vector2(Float.valueOf(posX) , Float.valueOf(posX));


        return e;
    }

    public static String createString(Entity e) {
        String s = "";

        if (e instanceof Player) {

            s += 1;

        }
        s += ":" + e.getId() + ":" + e.getPosition().getX() + ":" + e.getPosition().getY() + ";";;

        return s;
    }
}
